package com.matt.sooncleaner.arch.widget

import android.content.Context
import android.graphics.Color
import android.os.Build
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.cardview.widget.CardView
import com.matt.sooncleaner.R
import com.matt.sooncleaner.arch.dp
import com.matt.sooncleaner.databinding.MainNavigationCardBinding

class MainNavigationCard @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : CardView(context, attrs) {
    private val binding: MainNavigationCardBinding =
        MainNavigationCardBinding.inflate(LayoutInflater.from(context), this, false)

    init {
        addView(binding.root)
        setCardBackgroundColor(Color.WHITE)
        val ta = context.obtainStyledAttributes(attrs, R.styleable.MainNavigationCard)
        val title = ta.getString(R.styleable.MainNavigationCard_cardTitle)
        val icon = ta.getDrawable(R.styleable.MainNavigationCard_cardIcon)
        ta.recycle()
        binding.cardIcon.setImageDrawable(icon)
        binding.cardTitle.text = title
        cardElevation = 10f.dp
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            outlineAmbientShadowColor = resources.getColor(R.color.card_shadow_color)
        }
    }
}